package com.example.kechengsheji;

import android.content.ContentValues;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class jiesuan extends shouyin {
   TextView tv_nshowshangpin,tv_nshowmoney,tv_nshownum,tv_nsum,tv_ntotal,lingqian,should;
    private EditText truemoney;
    private Button zhaoling;
    final jiesuanhelp cdHelper=new jiesuanhelp(jiesuan.this);
    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.jiesuan);
        should=findViewById(R.id.should);
        tv_nshowshangpin=findViewById(R.id.tv_nshowshangpin);
        tv_nshowmoney=findViewById(R.id.tv_nshowmoney);
        tv_nshownum=findViewById(R.id.tv_nshownum);
        tv_nsum=findViewById(R.id.tv_nsum);
        truemoney=findViewById(R.id.truemoney);
        zhaoling=findViewById(R.id.zhaoling);
        lingqian=findViewById(R.id.lingqian);

        SQLiteDatabase cd=cdHelper.getReadableDatabase();

        //找零监听
        zhaoling.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //获得应付文本框内容，进行转换
                String yingfu =should.getText().toString();
                String zyingfu = String.valueOf(yingfu);
                double ing = Double.parseDouble(zyingfu.trim());
                ///获得输入框内容进行计算
                String ed = truemoney.getText().toString();
                double ted =Double.parseDouble(ed);
                double ling = ted-ing;
                lingqian.setText(null);
                lingqian.setText(lingqian.getText()+"\t"+ling);

                //插入数据库
                //jshangpin VARCHAR(20),jmoney INTEGER,jnum INTEGER,jsum INTEGER,
                // jzhaoling INTEGER,jyingfu INTEGER,jshifu INTEGER
                SQLiteDatabase cd=cdHelper.getWritableDatabase();
                ContentValues values=new ContentValues();
                values.put("实付",truemoney.getText().toString());
                values.put("找零",lingqian.getText().toString());
                values.put("应付",should.getText().toString());
                long id =cd.insert("information",null,values);
                Log.d("myDeBug","insert");
                cd.close();

            }
        });


        Intent intent = getIntent();
        should.setText( intent.getStringExtra("ntotal"));
        tv_nshowshangpin.setText(null);
        tv_nshowshangpin.setText( intent.getStringExtra("nshangpin"));
        tv_nshowmoney.setText(null);
        tv_nshowmoney.setText( intent.getStringExtra("ndanjia"));
        tv_nshownum.setText(null);
        tv_nshownum.setText( intent.getStringExtra("nshuliang"));
        tv_nsum.setText(null);
        tv_nsum.setText( intent.getStringExtra("nsum"));

    }
}
